﻿namespace Sidvall.WorkItemManager.UI.Entities
{
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Maintainability", "CA1506:AvoidExcessiveClassCoupling")]
    public sealed partial class WorkItemSensorLog : global::Sidvall.WorkItemManager.UI.Entities.Core.BusinessBase, global::Sidvall.WorkItemManager.Data.IWorkItemSensorLog
    {
        #region Business Members

        #region Value

        private string _Value = string.Empty;
        partial void OnBeforeValuePropertyGet(Sidvall.Business.PropertyEventData<string> eventData);
        partial void OnBeforeValuePropertyChanged(Sidvall.Business.PropertyChangeEventData<string> eventData);
        partial void OnAfterValuePropertyChanged();
        public string Value
        {
            get
            {
                Sidvall.Business.PropertyEventData<string> eventData = new Sidvall.Business.PropertyEventData<string>(_Value);
                OnBeforeValuePropertyGet(eventData);
                return eventData.Value;
            }
            set
            {
                Sidvall.Business.PropertyChangeEventData<string> eventData = new Sidvall.Business.PropertyChangeEventData<string>(value, _Value);
                OnBeforeValuePropertyChanged(eventData);
                if (!eventData.Cancel)
                {
                    LoadInstanceField("Value", eventData.Value, true, true, true);
                    OnAfterValuePropertyChanged();
                }
            }
        }

        #endregion
        #region ValueTimestamp

        private System.DateTime _ValueTimestamp = System.DateTime.UtcNow;
        partial void OnBeforeValueTimestampPropertyGet(Sidvall.Business.PropertyEventData<System.DateTime> eventData);
        partial void OnBeforeValueTimestampPropertyChanged(Sidvall.Business.PropertyChangeEventData<System.DateTime> eventData);
        partial void OnAfterValueTimestampPropertyChanged();
        public System.DateTime ValueTimestamp
        {
            get
            {
                Sidvall.Business.PropertyEventData<System.DateTime> eventData = new Sidvall.Business.PropertyEventData<System.DateTime>(Sidvall.Business.ValidationManager.GetValidDateTime(_ValueTimestamp));
                OnBeforeValueTimestampPropertyGet(eventData);
                return eventData.Value;
            }
            set
            {
                Sidvall.Business.PropertyChangeEventData<System.DateTime> eventData = new Sidvall.Business.PropertyChangeEventData<System.DateTime>(value, _ValueTimestamp);
                OnBeforeValueTimestampPropertyChanged(eventData);
                if (!eventData.Cancel)
                {
                    LoadInstanceField("ValueTimestamp", eventData.Value, true, true, true);
                    OnAfterValueTimestampPropertyChanged();
                }
            }
        }

        #endregion
        #region WorkItemSensorId

        private long _WorkItemSensorId = 0L;
        partial void OnBeforeWorkItemSensorIdPropertyGet(Sidvall.Business.PropertyEventData<long> eventData);
        partial void OnBeforeWorkItemSensorIdPropertyChanged(Sidvall.Business.PropertyChangeEventData<long> eventData);
        partial void OnAfterWorkItemSensorIdPropertyChanged();
        public long WorkItemSensorId
        {
            get
            {
                Sidvall.Business.PropertyEventData<long> eventData = new Sidvall.Business.PropertyEventData<long>(_WorkItemSensorId);
                OnBeforeWorkItemSensorIdPropertyGet(eventData);
                return eventData.Value;
            }
            set
            {
                Sidvall.Business.PropertyChangeEventData<long> eventData = new Sidvall.Business.PropertyChangeEventData<long>(value, _WorkItemSensorId);
                OnBeforeWorkItemSensorIdPropertyChanged(eventData);
                if (!eventData.Cancel)
                {
                    LoadInstanceField("WorkItemSensorId", eventData.Value, true, true, true);
                    OnAfterWorkItemSensorIdPropertyChanged();
                }
            }
        }

        #endregion
        #region WorkItemSensor

        private WorkItemSensor _WorkItemSensor;
        partial void OnBeforeWorkItemSensorPropertyChanged(Sidvall.Business.PropertyChangeEventData<WorkItemSensor> eventData);
        partial void OnAfterWorkItemSensorPropertyChanged();
        public WorkItemSensor WorkItemSensor
        {
            get
            {
                return _WorkItemSensor;
            }
            set
            {
                Sidvall.Business.PropertyChangeEventData<WorkItemSensor> eventData = new Sidvall.Business.PropertyChangeEventData<WorkItemSensor>(value, _WorkItemSensor);
                OnBeforeWorkItemSensorPropertyChanged(eventData);
                if (!eventData.Cancel)
                {
                    LoadInstanceField("WorkItemSensor", eventData.Value, true, true, false);
                    OnAfterWorkItemSensorPropertyChanged();
                }
            }
        }

        #endregion
        #region DataRowContextStorageKey

        protected override string DataRowContextStorageKey
        {
            get
            {
                return global::Sidvall.WorkItemManager.UI.SystemContext.Current.EntityFacade.WorkItemSensorLogManager.GetKey(this);
            }
        }

        #endregion
        #region DataRowIsValid

        public override bool DataRowIsValid(Sidvall.Data.BusinessRuleFilter filter)
        {
            return global::Sidvall.WorkItemManager.UI.SystemContext.Current.EntityFacade.WorkItemSensorLogManager.DataRowIsValid(this, filter);
        }

        #endregion
        #region DataRowStateIsDirty

        public override bool DataRowStateIsDirty
        {
            get
            {
                return global::Sidvall.WorkItemManager.UI.SystemContext.Current.EntityFacade.WorkItemSensorLogManager.DataRowStateIsDirty(this);
            }
        }

        #endregion

        #region LoadWorkItemSensorAsync

        public async System.Threading.Tasks.Task<WorkItemSensor> LoadWorkItemSensorAsync()
        {
            return await LoadWorkItemSensorAsync(false, true, null, null, null);
        }
        public async System.Threading.Tasks.Task<WorkItemSensor> LoadWorkItemSensorAsync(bool refresh, bool raisePropertyChanged, global::Sidvall.Data.FetchCriteria<global::Sidvall.WorkItemManager.Data.Fields.WorkItemSensorField, global::Sidvall.WorkItemManager.Data.Relations.WorkItemSensorRelation> criteria, string strategyContext, global::Sidvall.Data.ObjectParameterCollection objectParameters)
        {
            await global::Sidvall.WorkItemManager.UI.SystemContext.Current.DataPortal.WorkItemSensorLogManager.LoadWorkItemSensorAsync(this, refresh, raisePropertyChanged, criteria, strategyContext, objectParameters);

            return this.WorkItemSensor;
        }
        public WorkItemSensor LoadWorkItemSensor(WorkItemSensor item)
        {
            LoadInstanceField("WorkItemSensor", item, true, true, false);
            return item;
        }

        #endregion
        #region LoadInstanceField

        public void LoadInstanceField(string fieldName, object value, bool cascade, bool raisePropertyChanged, bool updateState)
        {
            global::Sidvall.WorkItemManager.UI.SystemContext.Current.EntityFacade.WorkItemSensorLogManager.LoadInstanceField(this, fieldName, value, cascade, raisePropertyChanged, updateState);
        }

        #endregion
        #region AcceptChanges

        public void AcceptChanges()
        {
            global::Sidvall.WorkItemManager.UI.SystemContext.Current.EntityFacade.WorkItemSensorLogManager.AcceptChanges(this);
        }

        #endregion
        #region Clone

        public WorkItemSensorLog Clone()
        {
            var copySettings = Sidvall.Data.CopySettings.Clone();
            return Copy(copySettings);
        }

        #endregion
        #region Copy

        public WorkItemSensorLog Copy()
        {
            return Copy(null);
        }
        public WorkItemSensorLog Copy(Sidvall.Data.CopySettings copySettings)
        {
            if (copySettings == null)
                copySettings = new Sidvall.Data.CopySettings();
            if (!Sidvall.Data.DataRowContextManager.IsValid(this, copySettings.RowFilter))
                return null;
            var item = new WorkItemSensorLog();
            Import(item, this, copySettings);
            return item;
        }

        #endregion
        #region Import

        public void Import(global::Sidvall.WorkItemManager.Data.IWorkItemSensorLog item)
        {
            Import(item, null);
        }
        public void Import(global::Sidvall.WorkItemManager.Data.IWorkItemSensorLog item, Sidvall.Data.CopySettings copySettings)
        {
            Import(this, item, copySettings);
        }
        partial void OnAfterImport(WorkItemSensorLog destination, global::Sidvall.WorkItemManager.Data.IWorkItemSensorLog source, Sidvall.Data.CopySettings copySettings);
        private void Import(WorkItemSensorLog destination, global::Sidvall.WorkItemManager.Data.IWorkItemSensorLog source, Sidvall.Data.CopySettings copySettings)
        {
            global::Sidvall.WorkItemManager.UI.SystemContext.Current.EntityFacade.WorkItemSensorLogManager.Import(destination, source, copySettings);
            OnAfterImport(destination, source, copySettings);
        }
        partial void OnAfterImport(WorkItemSensorLog destination, WorkItemSensorLog source, Sidvall.Data.CopySettings copySettings);
        private void Import(WorkItemSensorLog destination, WorkItemSensorLog source, Sidvall.Data.CopySettings copySettings)
        {
            Import(destination, source as global::Sidvall.WorkItemManager.Data.IWorkItemSensorLog, copySettings);
            OnAfterImport(destination, source, copySettings);
        }

        #endregion
        #region SaveItemAsync

        public async System.Threading.Tasks.Task<WorkItemSensorLog> SaveItemAsync()
        {
            return await global::Sidvall.WorkItemManager.UI.SystemContext.Current.DataPortal.WorkItemSensorLogManager.SaveItemAsync(this);
        }
        public async System.Threading.Tasks.Task<WorkItemSensorLog> SaveItemAsync(Sidvall.Data.SaveMode mode)
        {
            return await global::Sidvall.WorkItemManager.UI.SystemContext.Current.DataPortal.WorkItemSensorLogManager.SaveItemAsync(this, mode);
        }
        public async System.Threading.Tasks.Task<WorkItemSensorLog> SaveItemAsync(Sidvall.Data.SaveSettings settings)
        {
            return await global::Sidvall.WorkItemManager.UI.SystemContext.Current.DataPortal.WorkItemSensorLogManager.SaveItemAsync(this, settings);
        }
        public async System.Threading.Tasks.Task<WorkItemSensorLog> SaveItemAsync(Sidvall.Data.SaveSettings settings, string strategyContext, global::Sidvall.Data.ObjectParameterCollection objectParameters)
        {
            return await global::Sidvall.WorkItemManager.UI.SystemContext.Current.DataPortal.WorkItemSensorLogManager.SaveItemAsync(this, settings, strategyContext, objectParameters);
        }

        #endregion
        #region ValidateAsync

        public async System.Threading.Tasks.Task<Sidvall.Data.BusinessRuleCollection> ValidateAsync()
        {
            return await ValidateAsync((Sidvall.Data.ValidationSettings)null);
        }
        public async System.Threading.Tasks.Task<Sidvall.Data.BusinessRuleCollection> ValidateAsync(Sidvall.Data.ValidationSettings settings)
        {
            var context = new Sidvall.Business.ValidationContext(settings);
            await global::Sidvall.WorkItemManager.UI.SystemContext.Current.EntityFacade.WorkItemSensorLogManager.ValidateAsync(this, context);
            await ValidateAsync(context);
            return context.AllBusinessRules;
        }
        partial void OnAfterValidate(Sidvall.Data.BusinessRuleCollection itemBusinessRules, Sidvall.Business.ValidationContext context);
        public async System.Threading.Tasks.Task ValidateAsync(Sidvall.Business.ValidationContext context)
        {
            var itemBusinessRules = new Sidvall.Data.BusinessRuleCollection();
            OnAfterValidate(itemBusinessRules, context);
            await context.TaskContext.DoTaskAsync();
            context.AllBusinessRules.AddRange(context.Settings.IncludeNotBrokenRules, itemBusinessRules);
            var businessRulesProvider = this as Sidvall.Data.IBusinessRulesProvider;
            if (businessRulesProvider != null)
                businessRulesProvider.BusinessRules.AddRange(context.Settings.IncludeNotBrokenRules, itemBusinessRules);
        }

        #endregion
        #region Initialize

        public void Initialize()
        {
            global::Sidvall.WorkItemManager.UI.SystemContext.Current.EntityFacade.WorkItemSensorLogManager.Initialize(this);
        }
        public void Initialize(Sidvall.Data.InitializeSettings settings)
        {
            global::Sidvall.WorkItemManager.UI.SystemContext.Current.EntityFacade.WorkItemSensorLogManager.Initialize(this, settings);
        }

        #endregion
        
        #region IWorkItemSensorLog Members

        string global::Sidvall.WorkItemManager.Data.IWorkItemSensorLog.Value
        {
            get
            {
                return this._Value;
            }
            set
            {
                this._Value = value;
            }
        }
        System.DateTime global::Sidvall.WorkItemManager.Data.IWorkItemSensorLog.ValueTimestamp
        {
            get
            {
                return this._ValueTimestamp;
            }
            set
            {
                this._ValueTimestamp = value;
            }
        }
        long global::Sidvall.WorkItemManager.Data.IWorkItemSensorLog.WorkItemSensorId
        {
            get
            {
                return this._WorkItemSensorId;
            }
            set
            {
                this._WorkItemSensorId = value;
            }
        }
        global::Sidvall.WorkItemManager.Data.IWorkItemSensor global::Sidvall.WorkItemManager.Data.IWorkItemSensorLog.WorkItemSensor
        {
            get
            {
                return this._WorkItemSensor;
            }
            set
            {
                UpdateChildProperty(this._WorkItemSensor, value);
                this._WorkItemSensor = value as WorkItemSensor;
            }
        }

        #endregion

        #endregion
        #region Constructors

        public WorkItemSensorLog()
        {
        }

        public WorkItemSensorLog(Sidvall.Data.DataRowState? dataRowState)
            : base(dataRowState)
        {
        }

        #endregion
    }
}